<template>
  <a-spin :spinning="confirmLoading">
    <!--  带条件字典表下拉 -->
    <a-row :gutter="24">
      <a-col :span="24">
        <a-form-model-item label="一级课程名" prop="id">
          <j-dict-select-tag
            v-model="model.id"
            placeholder="请选择一级课程名"
            dictCode="course_type,type_name,id,LENGTH( type_code ) = 3 ORDER BY type_order"
          />
        </a-form-model-item>
      </a-col>
    </a-row>
    <a-input placeholder="子级菜单名" v-model="model.typeName" />
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { selAllPrimaryTitle, addTheSecondaryTitle } from '@api/api'

export default {
  name: 'CourseTypeForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      courseType: {},
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    this.primaryTitle()
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    submitForm() {
      const that = this
      this.courseType.id = this.model.id
      this.courseType.typeName = this.model.typeName
      addTheSecondaryTitle(this.courseType).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    primaryTitle() {
      selAllPrimaryTitle().then((res) => {
        this.model = res.result
        console.log(this.model)
      })
    },
  },
}
</script>